package com.itheima.controller;


import com.hmall.common.dto.PageDTO;
import com.itheima.pojo.ItemDoc;
import com.itheima.pojo.RequestParams;
import com.itheima.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/search")
@RestController
public class ItemController {

    @Autowired
    private ItemService itemService;


    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String key){
        return itemService.getSuggestions(key);
    }


    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams params){
        return itemService.getFilters(params);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params){
        return itemService.search(params);
    }


}
